import { apiUrl } from "@api/index";
import type {Dataset, ListDatasetParam, CreateDatasetParam, UpdateDatasetParam} from "@store/entity/dataset";
import { get, post, put, ToUrlSearchParams } from "@util/http";

export const listDatasets = async (val: ListDatasetParam): Promise<Dataset[]> => {
  
  return await get<Dataset[]>(apiUrl(`/dataset`), ToUrlSearchParams(val), { auth: true });
};

export const getDataset = async (key: number | string): Promise<Dataset> => {
  return await get<Dataset>(apiUrl(`/dataset/${key}`));
};

export const createDataset = async (val: CreateDatasetParam): Promise<Dataset> => {
  return await post<Dataset>(apiUrl(`/dataset`), val);
};

export const updateDataset = async (val: UpdateDatasetParam): Promise<Dataset> => {
  return await put<Dataset>(apiUrl(`/dataset/${val.id}`), val);
};

export const activeDataset = async (val: Dataset): Promise<Dataset> => {
  return await put<Dataset>(apiUrl(`/dataset/${val.id}/active`));
};

export const unactiveApp = async (val: Dataset): Promise<Dataset> => {
  return await put<Dataset>(apiUrl(`dataset/${val.id}/unactive`));
};
